package thinker.miracle.utils;

import java.util.Date;
import java.util.Random;

/**
 * @author bo.chen
 *
 */
public class MathUtil {

	/**
	 * 生成一个len位数组的字符串
	 * 
	 * @param len
	 * @return
	 */
	public static String randomNum(int len){
		StringBuffer sb = new StringBuffer();
		Random random = new Random();
		int i = 0;
		while (len > 0 && i < len){
			sb.append(random.nextInt(10));
			i++;
		}
		return sb.toString();
	}
	
    /**
     * 随机生成字母和字母
     * 
     * @param length
     * @return
     */
    public static String randomNumAndString(int length) {  
        String val = "";  
        Random random = new Random();
        //参数length，表示生成几位随机数  
        for(int i = 0; i < length; i++) {  
            String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num";  
            //输出字母还是数字  
            if( "char".equalsIgnoreCase(charOrNum) ) {  
                //输出是大写字母还是小写字母  
                int temp = random.nextInt(2) % 2 == 0 ? 65 : 97;  
                val += (char)(random.nextInt(26) + temp);  
            } else if( "num".equalsIgnoreCase(charOrNum) ) {  
                val += String.valueOf(random.nextInt(10));  
            }  
        }  
        return val;  
    }  
	
	/**
	 * 随机生成一个字符串
	 * 
	 * @return
	 */
	public static String nowTime(){
		String s =String.valueOf(new Date().getTime());
		return s;
	}
	
	/**
	 * 随机生成一个数字
	 * 
	 * @return
	 */
	public static String random(){
		return nowTime() + randomNum(6);
	}
}
